﻿package plugin.welcome
{
    import com.core.*;
    import com.sh.game.display.*;
    import com.sh.game.global.*;
    import flash.events.*;
    import flash.utils.*;
    import morn.core.handlers.*;
    import uiresource.welcome.*;

    public class NewWelcomeCtrl extends NewWelcomeUI
    {
        private var _close:Function;
        private var _timerInt:uint = 0;
        private var _curtype:int = 0;
        private var _inited:Boolean = false;
        private var welcomebtn:XMLMovieClip;
        public static const welcome:Class = NewWelcomeCtrl_welcome;

        public function NewWelcomeCtrl(param1:Function)
        {
            this._close = param1;
            return;
        }// end function

        override protected function initializeView() : void
        {
            super.initializeView();
            App.mloader3.loadSWF(Config.getUrl("assets/images/mainui/welcome.swf"), 1, new Handler(this.mcloaded));
            gamestartBtn.addEventListener(MouseEvent.CLICK, this.onStart);
            closebtn.addEventListener(MouseEvent.CLICK, this.onclose);
            this._inited = true;
            this._timerInt = setTimeout(this.timerHandler, 9000);
            gamestartBtn.addEventListener(MouseEvent.ROLL_OVER, this.showEffect);
            gamestartBtn.addEventListener(MouseEvent.ROLL_OUT, this.hideEffect);
            return;
        }// end function

        private function mcloaded(param1:Object) : void
        {
            var _loc_2:* = new XML(new welcome());
            this.welcomebtn = new XMLMovieClip("png.welcome", _loc_2);
            addChild(this.welcomebtn);
            this.welcomebtn.x = 331;
            this.welcomebtn.y = 229;
            this.welcomebtn.play();
            this.welcomebtn.mouseEnabled = false;
            this.welcomebtn.mouseChildren = false;
            return;
        }// end function

        private function hideEffect(event:MouseEvent) : void
        {
            if (this.welcomebtn)
            {
                this.welcomebtn.visible = true;
            }
            return;
        }// end function

        private function showEffect(event:MouseEvent) : void
        {
            if (this.welcomebtn)
            {
                this.welcomebtn.visible = false;
            }
            return;
        }// end function

        private function onclose(event:Event) : void
        {
            this.close();
            return;
        }// end function

        public function setType(param1:int) : void
        {
            this._curtype = param1;
            if (this._inited)
            {
                if (this._curtype == 0)
                {
                    if (this.welcomebtn)
                    {
                        this.welcomebtn.visible = true;
                    }
                }
                else if (this.welcomebtn)
                {
                    this.welcomebtn.visible = false;
                }
            }
            return;
        }// end function

        private function onStart(event:MouseEvent) : void
        {
            this.close();
            ModelProxy.change("zone", "stopGuaji", null);
            ModelProxy.change("data", "taskfindpath", 1001);
            ModelProxy.change("zone", "autoMove", {x:100, y:196, tostageid:1001});
            return;
        }// end function

        private function timerHandler() : void
        {
            if (this._timerInt > 0)
            {
                clearTimeout(this._timerInt);
                this._timerInt = 0;
            }
            this.close();
            return;
        }// end function

        private function close() : void
        {
            if (this._timerInt > 0)
            {
                clearTimeout(this._timerInt);
            }
            this._timerInt = 0;
            if (this._close != null)
            {
                this._close();
            }
            if (this.welcomebtn)
            {
                this.welcomebtn.dispose();
                this.removeChild(this.welcomebtn);
                this.welcomebtn = null;
            }
            return;
        }// end function

    }
}
